home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / fsutil / fsutilTrace.c < prev    next >
C/C++ Source or Header  |  1990-10-10  |  8KB  |  256 lines

  1. /* 
  2.  * fsTrace.c --
  3.  *
  4.  *    Subroutines for tracing file system events.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/kernel/fsutil/RCS/fsutilTrace.c,v 9.2 90/10/10 16:47:51 kupfer Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20.  
  21. #include <sprite.h>
  22.  
  23. #include <fs.h>
  24. #include <vm.h>
  25. #include <rpc.h>
  26. #include <fsutil.h>
  27. #include <fslcl.h>
  28. #include <fsNameOps.h>
  29. #include <fsprefix.h>
  30. #include <fsutilTrace.h>
  31. #include <fsStat.h>
  32. #include <sync.h>
  33. #include <timer.h>
  34. #include <proc.h>
  35. #include <trace.h>
  36. #include <hash.h>
  37. #include <fsrmt.h>
  38.  
  39. #include <stdio.h>
  40.  
  41. Trace_Header fsTraceHdr;
  42. Trace_Header *fsutil_TraceHdrPtr = &fsTraceHdr;
  43. int fsutil_TraceLength = 256;
  44. Boolean fsutil_Tracing = FALSE;
  45. Time fsTraceTime;        /* Cost of taking a trace record */
  46. int fsutil_TracedFile = -1;        /* fileID.minor of traced file */
  47.  
  48. typedef struct FsTracePrintTable {
  49.     Fsutil_TraceRecType    type;        /* This determines the format of the
  50.                      * trace record client data. */
  51.     char        *string;    /* Human readable record type */
  52. } FsTracePrintTable;
  53.  
  54. FsTracePrintTable fsTracePrintTable[] = {
  55.     /* TRACE_0 */        FST_BLOCK,     "delete block",
  56.     /* TRACE_OPEN_START */    FST_NAME,     "open start",
  57.     /* TRACE_LOOKUP_START */    FST_NAME,     "after prefix",
  58.     /* TRACE_LOOKUP_DONE */    FST_NAME,     "after lookup",
  59.     /* TRACE_DEL_LAST_WR */    FST_HANDLE,     "delete last writer",
  60.     /* TRACE_OPEN_DONE */    FST_NAME,     "open done",
  61.     /* TRACE_BLOCK_WAIT */    FST_BLOCK,    "skip block",
  62.     /* TRACE_BLOCK_HIT */    FST_BLOCK,     "hit block",
  63.     /* TRACE_DELETE */        FST_HANDLE,     "delete",
  64.     /* TRACE_NO_BLOCK */    FST_BLOCK,     "new block",
  65.     /* TRACE_OPEN_DONE_2 */    FST_NAME,     "after Fs_Open",
  66.     /* TRACE_OPEN_DONE_3 */    FST_NIL,     "open complete",
  67.     /* INSTALL_NEW */        FST_HANDLE,    "inst. new",
  68.     /* INSTALL_HIT */        FST_HANDLE,    "inst. hit",
  69.     /* RELEASE_FREE */        FST_HANDLE,    "rels. free",
  70.     /* RELEASE_LEAVE */        FST_HANDLE,    "rels. leave",
  71.     /* REMOVE_FREE */        FST_HANDLE,    "remv. free",
  72.     /* REMOVE_LEAVE */        FST_HANDLE,    "remv. leave",
  73.     /* SRV_WRITE_1 */        FST_IO,        "invalidate",
  74.     /* SRV_WRITE_2 */        FST_IO,        "srv write",
  75.     /* SRV_GET_ATTR_1 */    FST_NIL,    "srv get attr 1",
  76.     /* SRV_GET_ATTR_2 */    FST_NIL,    "srv get attr 2",
  77.     /* OPEN */            FST_NIL,    "open",
  78.     /* READ */            FST_IO,     "read",
  79.     /* WRITE */            FST_IO,     "write",
  80.     /* CLOSE */            FST_HANDLE,     "close",
  81.     /* TRACE_RA_SCHED */    FST_RA,     "Read ahead scheduled",
  82.     /* TRACE_RA_BEGIN */    FST_RA,        "Read ahead started",
  83.     /* TRACE_RA_END */        FST_RA,         "Read ahead completed",
  84.     /* TRACE_DEL_BLOCK */    FST_BLOCK,     "Delete block",
  85.     /* TRACE_BLOCK_WRITE */    FST_BLOCK,    "Block write",
  86.     /* TRACE_GET_NEXT_FREE */    FST_HANDLE,    "get next free",
  87.     /* TRACE_LRU_FREE */    FST_HANDLE,    "lru free",
  88.     /* TRACE_LRU_DONE_FREE */    FST_HANDLE,    "lru done free",
  89. };
  90. static int numTraceTypes = sizeof(fsTracePrintTable)/sizeof(FsTracePrintTable);
  91.  
  92. /*
  93.  *----------------------------------------------------------------------
  94.  *
  95.  * Fsutil_TraceInit --
  96.  *
  97.  *    Initialize the filesystem trace record.  This also determines
  98.  *    the cost of taking the trace records so this cost can be
  99.  *    subtracted out when the records are displayed.
  100.  *
  101.  * Results:
  102.  *    None.
  103.  *
  104.  * Side effects:
  105.  *    Calls Trace_Init and Trace_Insert
  106.  *
  107.  *----------------------------------------------------------------------
  108.  */
  109. int
  110. Fsutil_TraceInit()
  111. {
  112.     Trace_Record *firstPtr, *lastPtr;
  113.  
  114.     Trace_Init(fsutil_TraceHdrPtr, fsutil_TraceLength, sizeof(Fsutil_TraceRecord), 0);
  115.     /*
  116.      * Take 10 trace records with a NIL data field.  This causes a
  117.      * bzero inside Trace_Insert, which is sort of a base case for
  118.      * taking a trace.  The time difference between the first and last
  119.      * record is used to determine the cost of taking the trace records.
  120.      */
  121.     firstPtr = &fsutil_TraceHdrPtr->recordArray[fsutil_TraceHdrPtr->currentRecord];
  122.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  123.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  124.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  125.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  126.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  127.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  128.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  129.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  130.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  131.     Trace_Insert(fsutil_TraceHdrPtr, 0, (ClientData)NIL);
  132.     lastPtr = &fsutil_TraceHdrPtr->recordArray[fsutil_TraceHdrPtr->currentRecord-1];
  133.  
  134.     Time_Subtract(lastPtr->time, firstPtr->time, &fsTraceTime);
  135.     Time_Divide(fsTraceTime, 9, &fsTraceTime);
  136.  
  137.     return 0;
  138. }
  139.  
  140. /*
  141.  *----------------------------------------------------------------------
  142.  *
  143.  * Fsutil_PrintTraceRecord --
  144.  *
  145.  *    Format and print the client data part of a filesystem trace record.
  146.  *
  147.  * Results:
  148.  *    None.
  149.  *
  150.  * Side effects:
  151.  *    printfs to the display.
  152.  *
  153.  *----------------------------------------------------------------------
  154.  */
  155. int
  156. Fsutil_PrintTraceRecord(clientData, event, printHeaderFlag)
  157.     ClientData clientData;    /* Client data in the trace record */
  158.     int event;            /* Type, or event, from the trace record */
  159.     Boolean printHeaderFlag;    /* If TRUE, a header line is printed */
  160. {
  161.     if (printHeaderFlag) {
  162.     /*
  163.      * Print column headers and a newline.
  164.      */
  165.     printf("%10s %17s %8s\n", "Delta  ", "<File ID>  ", "Event ");
  166.     printf("Cost of taking an fs trace record is %d.%06d\n",
  167.              fsTraceTime.seconds, fsTraceTime.microseconds);
  168.     }
  169.     if (clientData != (ClientData)NIL) {
  170.     if (event >= 0 && event < numTraceTypes) {
  171.         printf("%20s ", fsTracePrintTable[event].string);
  172.         switch(fsTracePrintTable[event].type) {
  173.         case FST_IO: {
  174.             Fsutil_TraceIORec *ioRecPtr = (Fsutil_TraceIORec *)clientData;
  175.             printf("<%2d, %2d, %1d, %4d> ",
  176.             ioRecPtr->fileID.type, ioRecPtr->fileID.serverID,
  177.             ioRecPtr->fileID.major, ioRecPtr->fileID.minor);
  178.             printf(" off %d len %d ", ioRecPtr->offset,
  179.                           ioRecPtr->numBytes);
  180.             break;
  181.         }
  182.         case FST_NAME: {
  183.             char *name = (char *)clientData;
  184.             name[39] = '\0';
  185.             printf("\"%s\"", name);
  186.             break;
  187.         }
  188.         case FST_HANDLE: {
  189.             Fsutil_TraceHdrRec *recPtr = (Fsutil_TraceHdrRec *)clientData;
  190.             printf("<%2d, %2d, %1d, %4d> ref %d blocks %d ",
  191.               recPtr->fileID.type, 
  192.               recPtr->fileID.serverID,
  193.               recPtr->fileID.major, 
  194.               recPtr->fileID.minor,
  195.               recPtr->refCount,
  196.               recPtr->numBlocks);
  197.             break;
  198.         }
  199.         case FST_BLOCK: {
  200.             Fsutil_TraceBlockRec *blockPtr = (Fsutil_TraceBlockRec *)clientData;
  201.             printf("<%2d, %2d, %1d, %4d> block %d flags %x ",
  202.               blockPtr->fileID.type, 
  203.               blockPtr->fileID.serverID,
  204.               blockPtr->fileID.major, 
  205.               blockPtr->fileID.minor,
  206.               blockPtr->blockNum,
  207.               blockPtr->flags);
  208.               break;
  209.         }
  210.         case FST_RA: {
  211.             int    *blockNumPtr;
  212.  
  213.             blockNumPtr = (int *) clientData;
  214.             printf("<Block=%d> ", *blockNumPtr);
  215.             break;
  216.         }
  217.         case FST_NIL:
  218.         default:
  219.             break;
  220.         }
  221.     } else {
  222.         printf("(%d)", event);
  223.     }
  224.     }
  225.     return 0;
  226. }
  227.  
  228. /*
  229.  *----------------------------------------------------------------------
  230.  *
  231.  * Fsutil_PrintTrace --
  232.  *
  233.  *    Dump out the fs trace.
  234.  *
  235.  * Results:
  236.  *    None.
  237.  *
  238.  * Side effects:
  239.  *    None.
  240.  *
  241.  *----------------------------------------------------------------------
  242.  */
  243.  
  244. void
  245. Fsutil_PrintTrace(clientData)
  246.     ClientData clientData;
  247. {
  248.     int numRecs = (int) clientData;
  249.  
  250.     if (numRecs < 0) {
  251.     numRecs = fsutil_TraceLength;
  252.     }
  253.     printf("FS TRACE\n");
  254.     (void)Trace_Print(fsutil_TraceHdrPtr, numRecs, Fsutil_PrintTraceRecord);
  255. }
  256.